from rest_framework import serializers
from rest_framework.validators import UniqueValidator
from .models import User
from .models import FileModel

class UserSerializer(serializers.ModelSerializer):

    class Meta:
        model = User
        fields = ['id', 'name', 'email']
        extra_kwargs = {
            'email': {'validators': [UniqueValidator(queryset=User.objects.all())]}  # 数据验证, 邮箱唯一
        }

class FileSerializer(serializers.ModelSerializer):
    
    class Meta:
        model = FileModel
        fields = ['id', 'file']